package com.wzh.codegen.biz.controller;

import com.wzh.codegen.biz.domain.dto.CodegenServiceDTO;
import com.wzh.codegen.biz.service.CodegenService;
import com.wzh.common.general.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 微服务代码生成控制器，提供基于数据库表结构的代码生成接口
 * </p>
 *
 * @author 山归岿
 * @create 2025-06-15-19:42
 */
@Tag(name = "微服务代码生成", description = "微服务代码生成相关接口")
@RestController
@RequestMapping("/service")
@RequiredArgsConstructor
public class CodegenController {

    private final CodegenService codegenService;

    @Operation(summary = "生成微服务代码")
    @PostMapping
    public Result<String> generateService(@Valid @RequestBody CodegenServiceDTO dto) {
        String result = codegenService.generateService(dto);
        return Result.success(result);
    }

    @Operation(summary = "下载微服务代码压缩包")
    @PostMapping("/download")
    public ResponseEntity<Resource> downloadService(@Valid @RequestBody CodegenServiceDTO dto) {
        return codegenService.downloadService(dto);
    }

}